package jsyf.oa.service.tmp;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.oa.dao.tmp.OilDao;
import jsyf.oa.entity.tmp.OilEntity;
import jsyf.oa.facade.tmp.OilFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

/**
 * Created by jjx on 2018/3/6.
 */
@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class OilService implements OilFacade {

    @Autowired
    private OilDao oilDao;


    @Override
    public JSONObject getById(String jsonData) {
        return oilDao.getJSONById(JSON.parseObject(jsonData).getString("ID"));
    }

    @Override
    public String add(String jsonData) {
        OilEntity entity = JSON.toJavaObject(JSON.parseObject(jsonData), OilEntity.class);
        oilDao.add(entity);
        return entity.getId();
    }

    @Override
    public Boolean delById(String jsonData) {

        return oilDao.delById(JSON.parseObject(jsonData).getString("ID"))>0;
    }

    @Override
    public Boolean removeById(String jsonData) {
        return oilDao.removeById(JSON.parseObject(jsonData).getString("ID"))>0;
    }

    @Override
    public Boolean update(String jsonData) {
        OilEntity entity = JSON.toJavaObject(JSON.parseObject(jsonData), OilEntity.class);
        return oilDao.update(entity)>0;
    }
}
